﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace DemoForLinq.Chapter1
{
    class Demo1_2_LinqToXml
    {
        static void Main(string[] args)
        {
            XElement books = XElement.Parse(
                @"<books>
                    <book>
                        <title>Pro LINQ: Language Intergrated Query in C# 2008</title>
                        <author>Joe Rattz</author>
                    </book>
                    <book>
                        <title>Pro WF: Windows Workflow in .NET 3.0</title>
                        <author>Bruce Bukovics</author>
                    </book>
                    <book>
                        <title>Pro in C# 2005 and the .NET 2.0 Platform, Third Edition</title>
                        <author>Andrew Troelsen</author>
                    </book>
                </books>");
            var titles = from book in books.Elements("book")
                         where (string)book.Element("author") == "Joe Rattz"
                         select book.Element("title");
            foreach (var title in titles)
            {
                Console.WriteLine(title.Value);
            }

        }
    }
}
